#include "stdafx.h"
#include "TalkingDialogueBox.h"
#include "TextureManager.h"
#include "BMPText.h"

#define TIC_TIME .07f
TalkingDialogueBox::TalkingDialogueBox() : m_nTotalCharacters(0), 
m_fCharacterTicker(TIC_TIME), m_nCurrentCharacter(0)
{

}

TalkingDialogueBox::~TalkingDialogueBox()
{

}

void TalkingDialogueBox::Update(float _dt)
{
	m_fCharacterTicker -= _dt;
	if(m_fCharacterTicker < 0.0f && m_nCurrentCharacter < m_nTotalCharacters)
	{
		m_nCurrentCharacter++;
		m_fCharacterTicker = TIC_TIME;
	}
}

void TalkingDialogueBox::Render()
{ 
 	TextureManager::GetInstance()->Draw(m_pBackground->GetTextureID(), 0, 0, 0.955f, 0.6f);
 	BMPText::GetInstance()->DrawWithFontLimitedText(m_nCurrentCharacter, m_pFont->GetFontID(), m_szDialogue.c_str(),25,25,D3DCOLOR_XRGB(255,255,255), 1.0f);
 	//m_pFont->Render();
 }

void TalkingDialogueBox::SetupDialogueBox(char* szDialogue, char* szSpeaker, char* szBg, int nFont)
{
	m_szSpeaker = szSpeaker;
	m_szDialogue = szDialogue;
	m_nTotalCharacters = m_szDialogue.size();

	m_nFontID = nFont;


	m_pFont = new BitmapTextObject();
	m_pBackground = new BitmapTextObject();

	m_pBackground->SetTextureID(TextureManager::GetInstance()->LoadTexture(szBg));
	m_pFont->SetText(nFont, szDialogue, D3DXVECTOR2(0,400));
}